package jdbc3_25;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

public class JDBCDemo08 {
    public static void main(String[] args) {
      try (Connection connection = DBUtil.getConnection()){
          Scanner scanner = new Scanner(System.in);
          System.out.println("请输入用户名、密码、昵称、年龄");
          String username = scanner.nextLine();
          String password = scanner.nextLine();
          String nickname= scanner.nextLine();
          int age = scanner.nextInt();
       String sql = "INSERT INTO user(username,password,nickname,age) "+
       "VALUES (?,?,?,?)";
          PreparedStatement ps = connection.prepareStatement(sql);
         ps.setString(1,username);
         ps.setString(2,password);
         ps.setString(3,nickname);
         ps.setInt(4,age);
          ResultSet rs = ps.executeQuery();
          System.out.println(rs.next()?"注册成功":"注册失败");
      }catch (Exception e){
          e.printStackTrace();
      }
    }
}
